// TimeData Comparer - Comparer for sorting TimeData objects by Signature.
// Copyright (C) 2009  Robert N. Tenney
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Collections.Generic;


namespace RTenney.Utility.Timekeeping {
    /// <summary>
    /// Description of TimeDataSignatureComparer.
    /// </summary>
    public class TimeDataMethodComparer : IComparer<TimeData> {
        /// <summary>
        /// Compares the Signature of one TimeData object with another TimeData object.
        /// </summary>
        /// <param name="x">First TimeData object.</param>
        /// <param name="y">Second TimeData object.</param>
        /// <returns></returns>
        public int Compare(TimeData x, TimeData y) {

            if (x.ClassName == null) {
                if (y.ClassName == null) {
                    // If x is null and y is null, they're
                    // equal.
                    return 0;
                } else {
                    // If x is null and y is not null, y
                    // is greater.
                    return -1;
                }
            } else {
                string xClass = x.ClassName + "." + x.MethodName;
                // If x is not null...
                //
                if (y.Signature == null)
                    // ...and y is null, x is greater.
                {
                    return 1;
                } else {
                    string yClass = y.ClassName + "." + y.MethodName;
                    return xClass.CompareTo(yClass);
                }
                //                }
            }
        }
    }
}

